import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        count: 0,
        num: 0
    },
    mutations: {
        add(state) {
            state.count++;
        },
        kill(state) {
            state.count--;
        },
        addN(state, payload) {
            state.count += payload.n
        }
    },
    actions: {
        addWait(store) {
            setTimeout(() => {
                store.commit("add")
            }, 2000)
        },
        addNWait(store, n) {
            setTimeout(() => {
                store.commit("addN", {
                    n: n
                })
            }, 2000)
        }
    },

    getters:{
        dbCount(state){
            return state.count*2;
        }
    }
})